{extend name="global" /} {block name="body"}
<div class="ibox-content">

    <a class="btn btn-primary import-excel " href="#" class="">
        <i class="fa fa-plus"></i>导入excel数据
    </a>
    
    <table  id="demo" class="layui-table table-hover"  lay-filter="test">
        
    </table>
    {/block}
     {block name='js'} 

    <script type="text/javascript">
        //依赖于jQuery的代码
    layui.use(['laypage', 'table', 'element', 'layer', 'jquery','form','upload'], function () {  
        var upload = layui.upload;
        var element = layui.element;
        var table = layui.table;
        jq = layui.jquery;
        var flag = false;

        table.render({
                    elem: '#demo'
                    
                    ,url: '{:url("run/index/tableData")}' //数据接口
                    ,page: true //开启分页
                    ,height:500
                    ,limit:10
                    ,cols: [[ //表头
                    {field: 'id', title: 'ID',sort: true, fixed: 'left'}
                    ,{field: 'license_plate_number', title: '车牌号'}
                    ,{field: 'vin', title: '车架号'}
                    ,{field: 'engine_no', title: '发动机号'}
                    
                     
                    ]]
        });
        $('.import-excel').on('click',function(){ 
        var openClose = layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['50%', ''], //宽高
            content: '<div style="text-align:center;padding:20px 0"><button type="button" class="layui-btn" id="test1"><i class="layui-icon">&#xe67c;</i>上传excel文件</button></div>'
        });
        upload.render({
            url: '{:url("run/index/importExcel")}',
            elem: '#test1',
            // ext: 'jpg|png|gif|jpeg',
            accept:'xls',
            exts:'xls',
            acceptMime: 'xls/*',
            area: ['500', '500px'],
            before: function (input) {
                loading = layer.load(2, {
                    shade: [0.2, '#000']
                });
            },
            done: function (res) {
                console.log(res)
                if(res.status==1){ 
                    layer.close(loading);
               layer.close(openClose);
                  //第一个实例
                table.render({
                    elem: '#demo'
                    
                    ,url: '{:url("run/index/tableData")}' //数据接口
                    ,page: true //开启分页
                    ,cols: [[ //表头
                    {field: 'id', title: 'ID',sort: true, fixed: 'left'}
                    ,{field: 'license_plate_number', title: '车牌号'}
                    ,{field: 'vin', title: '车架号'}
                    ,{field: 'engine_no', title: '发动机号'}
                     
                    ]]
                });
            }

            },
            error: function (res) {
                if(res.status==1){

                }else{

                }
                layer.close(loading);
                console.log(res)

                // alert(res);
            }
        });
    })
  
}); 
    
            
                
        
 
    </script>
    {/block}